#coding=utf-8
from django.shortcuts import render_to_response, redirect
from django.http import HttpResponse, HttpResponseRedirect
from redirector.models import Resource, Person, AccessRecord

def access(request, resource_id):
  own_id = request.GET['own_id']
  
  r = Resource.objects.get(id=resource_id)

  p = Person.objects.get_or_create(own_id=own_id)[0]
  
  a = AccessRecord(p=p, r=r)  
  a.save()
  
  r.times += 1
  r.save()
  
  return redirect(r.url)

